<div class="content-wrapper">
    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>
        <h1 class="pull-right" id="dbshop-menu-top">
            <?php echo $this->HelpUrl('userRanking'); ?>
        </h1>
    </section>

    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box">
                    <div class="box-body">
                        <h2 class="page-header">
                            <?php echo $this->translate('客户排行'); ?>
                        </h2>
                        <div class="row">
                            <div class="col-xs-12">
                                <?php
                                $form = $this->form;
                                $form->prepare();
                                echo $this->form()->openTag($form);
                                ?>
                                <div class="col-xs-5 text-right">
                                    <a href="<?php echo $this->url('analysis', ['action' => 'userRanking'], ['query' => ['userGroupId' => $form->get('userGroupId')->getValue()]]); ?>" class="btn <?php echo $this->type == 'today' ? 'btn-primary' : 'btn-default'; ?>"><?php echo $this->translate('今日'); ?></a>
                                    &nbsp;&nbsp;
                                    <a href="<?php echo $this->url('analysis', ['action' => 'userRanking'], ['query' => ['type' => 'week', 'userGroupId' => $form->get('userGroupId')->getValue()]]); ?>" class="btn <?php echo $this->type == 'week' ? 'btn-primary' : 'btn-default'; ?>"><?php echo $this->translate('本周'); ?></a>
                                    &nbsp;&nbsp;
                                    <a href="<?php echo $this->url('analysis', ['action' => 'userRanking'], ['query' => ['type' => 'month', 'userGroupId' => $form->get('userGroupId')->getValue()]]); ?>" class="btn <?php echo $this->type == 'month' ? 'btn-primary' : 'btn-default'; ?>"><?php echo $this->translate('本月'); ?></a>
                                </div>
                                <div class="col-xs-2">
                                    <?php echo $this->formElement($form->get('userGroupId')); ?>
                                </div>
                                <div class="col-xs-2">
                                    <div class="input-group">
                                        <span class="input-group-addon"><i class="fa fa-calendar" aria-hidden="true"></i></span>
                                        <?php echo $this->formElement($form->get('startDate')); ?>
                                    </div>
                                </div>
                                <div class="col-xs-2">
                                    <div class="input-group">
                                        <span class="input-group-addon"><i class="fa fa-calendar" aria-hidden="true"></i></span>
                                        <?php echo $this->formElement($form->get('endDate')); ?>
                                    </div>
                                </div>
                                <div class="col-xs-1">
                                    <button type="submit" class="btn btn-info"><?php echo $this->translate('查看'); ?></button>
                                </div>
                                <?php echo $this->form()->closeTag(); ?>
                            </div>
                        </div>
                    </div>
                    <form name="ranking-list-form" id="ranking-list-form" method="get">
                        <div class="box-body table-responsive no-padding">
                            <table class="table shop-table table-hover">
                                <thead>
                                <tr class="shop-bg-thead">
                                    <th width="10%"><?php echo $this->translate('排行'); ?></th>
                                    <th width="30%"><?php echo $this->translate('客户名称'); ?></th>
                                    <th width="20%"><?php echo $this->translate('客户等级'); ?></th>
                                    <th width="20%"><?php echo $this->translate('订单数量(已付款或货到付款)'); ?></th>
                                    <th width="20%"><?php echo $this->translate('购物金额'); ?></th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php
                                $basePageNum = $this->userRankingList->getItemCountPerPage() * ($this->userRankingList->getCurrentPageNumber()-1);
                                if ($this->userRankingList && $this->userRankingList->getTotalItemCount() > 0) { foreach ($this->userRankingList as $rankingKey => $rankingValue) { ?>
                                    <tr>
                                        <td>
                                            <input type="hidden" name="userId[]" value="<?php echo $rankingValue[0]->getUserId(); ?>">
                                            <?php echo $basePageNum + $rankingKey + 1; ?>
                                        </td>
                                        <td><?php echo $this->escapeHtml($rankingValue[0]->getUserName()); ?></td>
                                        <td><?php echo $this->escapeHtml($rankingValue[0]->getOneUserGroup()->getUserGroupName()); ?></td>
                                        <td id="orderNum<?php echo $rankingValue[0]->getUserId(); ?>"><i class="fa fa-spinner fa-pulse fa-lg fa-fw"></i><?php //echo $rankingValue['orderNum']; ?></td>
                                        <td><?php echo $rankingValue['orderTotal'] > 0 ? $rankingValue['orderTotal'] : '0'; ?></td>
                                    </tr>
                                <?php } } else { ?>
                                    <tr><td colspan="5"><h4><?php echo $this->translate('当前时间段无购物客户'); ?></h4></td></tr>
                                <?php } ?>
                                </tbody>
                            </table>
                        </div>
                        <div class="box-footer clearfix">
                            <input type="hidden" name="startTime" id="startTime" value="<?php echo $this->startTime; ?>">
                            <input type="hidden" name="endTime" id="endTime" value="<?php echo $this->endTime; ?>">
                            <?php echo $this->paginationControl($this->userRankingList, 'Sliding', 'layout/page', ['route' => 'analysis', 'params' => ['action' => 'userRanking']]); ?>
                        </div>
                    </form>
                </div>
            </div>
        </div>

    </section>
</div>
<script type="text/javascript">
    laydate.render({elem: '#startDate'});
    laydate.render({elem: '#endDate'});

    $.post("<?php echo $this->url('analysis', ['action' => 'ajaxUserOrderNum']); ?>", $('#ranking-list-form').formSerialize(),
        function(data){
            if(data.state == 'true') {
                console.log(data.orderNum);
                for (let i = 0; i < data.orderNum.length; i++) {
                    $('#orderNum'+data.orderNum[i].userId).html(data.orderNum[i].orderNum);
                }
            }
        }, 'json');
</script>